package com.cskaoyan.service.vx;

import com.cskaoyan.bean.vo.vxVo.*;
import com.cskaoyan.mapper.wxMapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WxHomeServiceImpl implements WxHomeService{
    @Autowired
    MarketGoodsMapper marketGoodsMapper;

    @Autowired
    MarketBrandMapper marketBrandMapper;

    @Autowired
    MarketAdMapper marketAdMapper;

    @Autowired
    MarketCategoryMapper marketCategoryMapper;

    @Autowired
    MarketCouponMapper marketCouponMapper;

    @Autowired
    MarketTopicMapper marketTopicMapper;

    @Override
    public WxHomeIndexPageVO getHomeIndex() {
        List<WxIndexGoodsVO> newGoods = marketGoodsMapper.selectGoodsIsNew();
        List<WxIndexGoodsVO> hotGoods = marketGoodsMapper.selectGoodsIsHot();
        List<WxIndexCouponVO> couponVOList = marketCouponMapper.selectAllCoupon();
        List<WxIndexChannelVO> channelVOList = marketCategoryMapper.selectCateCategoryByPId(0);
        List<WxIndexBannerVO> bannerVOList = marketAdMapper.selectEnableAd();
        List<WxIndexBrandVO> brandVOList = marketBrandMapper.selectBrand();
        List<WxIndexTopicVO> topicVOList = marketTopicMapper.selectTopic();
        List<WxIndexFloorGoods> floorGoodsList = marketGoodsMapper.selectGoodsAndClassify();
        for (WxIndexFloorGoods wxIndexFloorGoods : floorGoodsList) {
            if (wxIndexFloorGoods.getGoodsList().size() > 6) {
                List<WxIndexGoodsVO> wxIndexGoodsVOS = wxIndexFloorGoods.getGoodsList().subList(0, 6);
                wxIndexFloorGoods.setGoodsList(wxIndexGoodsVOS);
            }
        }
        WxHomeIndexPageVO homeIndexPageVO = new WxHomeIndexPageVO();
        homeIndexPageVO.setBanner(bannerVOList);
        homeIndexPageVO.setChannel(channelVOList);
        homeIndexPageVO.setBrandList(brandVOList);
        homeIndexPageVO.setCouponList(couponVOList);
        homeIndexPageVO.setHotGoodsList(hotGoods);
        homeIndexPageVO.setFloorGoodsList(floorGoodsList);
        homeIndexPageVO.setNewGoodsList(newGoods);
        homeIndexPageVO.setTopicList(topicVOList);

        return homeIndexPageVO;
    }
}
